//
//  AppDelegate.m
//  SegmentDemo
//
//  Created by 塔兮 on 2022/4/11.
//

#import "AppDelegate.h"

@interface AppDelegate ()

@end

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
    self.window.backgroundColor = UIColorFromHex(@"FFFFFF");
    self.window.rootViewController = [self rootViewController];
    [self.window makeKeyAndVisible];
    return YES;
}

- (UIViewController *)rootViewController {
    ListViewController *list = [ListViewController new];
    return [self makeNavigationWithRootController:list];
}

- (UINavigationController *)makeNavigationWithRootController:(UIViewController *)viewController {
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:viewController];
    nav.navigationBar.backgroundColor = UIColorFromHex(@"FFFFFF");
    [nav.navigationBar setBackgroundImage:[self createImageWithColor:UIColorFromHex(@"FFFFFF")] forBarMetrics:(UIBarMetricsDefault)];
    [nav.navigationBar setShadowImage:[UIImage new]];
    nav.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName:UIColorFromHex(@"000000")};
    nav.navigationBar.backIndicatorImage = [UIImage imageNamed:@"tx_back"];
    nav.navigationBar.backIndicatorTransitionMaskImage = [UIImage imageNamed:@"tx_back"];
    return nav;
}

- (UIImage *)createImageWithColor:(UIColor *) color {
    CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetFillColorWithColor(context, [color CGColor]);
    CGContextFillRect(context, rect);
    UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return theImage;
}

@end
